<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    #app {
      width: 375px;
      height: 667px;
      border: 1px solid #000;
      display: flex;
      flex-direction: column;
    }

    header {
      width: 100%;
      height: 45px;
      border-bottom: 1px solid #000;
      display: flex;
      justify-content: center;
      align-items: center;
    }

    main {
      flex: 1;
    }

    .item {
      width: 345px;
      height: 100px;
      border: 1px solid #000;
      margin: 15px;
    }

    footer {
      width: 100%;
      height: 50px;
      border-top: 1px solid #000;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  </style>
</head>
<body>
  <div id="app">
    <div :style="{fontSize: size + 'px'}">
      <wb-header @tobig="tobig"></wb-header>
      <wb-main></wb-main>
      <wb-footer></wb-footer>
    </div>
  </div>

  <script src="../Vue.js"></script>

  <script>
    const { createApp } = Vue;


    // 创建一个微博的列表的Item组件
    const WbItem = {
      props: ["title", "content"],
      template: `
        <div class="item">
          <h3>{{title}}</h3>
          <p>{{content}}</p>
          <button>👍</button>
        </div>
      `
    }

    // 创建三个根组件下面的组件
    const WbHeader = {
      template: `
        <header>
          微博
          <button @click="fn(1)">+</button>
          <button @click="fn(-1)">-</button>
        </header>
      `,
      methods: {
        fn(n) {
          this.$emit("tobig", n)
        }
      }
    };

    const WbMain = {
      data() {
        return {
          list: [
            {
              id: 1,
              title: "美军两架飞机在南海坠毁后",
              content: "中新网10月28日电 据美国福克斯新闻网报道"
            },
            {
              id: 2,
              title: "特朗普谈2028大选",
              content: "距离2028年美国总统大选尚有数年，美国政坛的“特朗普变量”已提前搅动风云。"
            },
            {
              id: 3,
              title: "英国想拉美欧搞“西方钢铁联盟”",
              content: "本月初，欧盟效仿美国、加拿大，对进口钢铁加征关税。"
            }
          ]
        }
      },
      template: `
        <main>
          <wb-item 
            v-for="item in list"
            :key="item.id"
            :title="item.title"
            :content="item.content"
          ></wb-item>
        </main>
      `,
      components: {
        WbItem
      }
    }

    const WbFooter = {
      template: `
        <footer>
          <input type="text" />
          <button>提交</button>
        </footer>
      `
    }

    createApp({
      data() {
        return {
          size: 14
        }
      },
      methods: {
        tobig(n) {
          this.size += n
        }
      },
      components: {
        WbHeader,
        WbMain,
        WbFooter
      }
    }).mount("#app")

  </script>
</body>
</html>